package io.dcloud.player;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;

import io.dcloud.player.widget.EWebView;

/**
 * Created by lxy on 2017/4/20.
 */

public class PlayerActivity extends AppCompatActivity {

    private LinearLayout ll_web;
    private PlayerFragment player;
    private EWebView web;

    /**
     *
     * @param context
     * @param url1 该url是文字和图片的url
     * @param url2 该url是点击“在线预约”跳转的url
     * @param rtmp rtmp是拉流的url
     */
    public static void toPlayerActivity(Context context,String url1,String url2,String rtmp){
        Intent intent = new Intent(context,PlayerActivity.class);
        intent.putExtra("url1",url1);
        intent.putExtra("url2",url2);
        intent.putExtra("rtmp",rtmp);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_player);

        ll_web = (LinearLayout) findViewById(R.id.ll_web);
        player = (PlayerFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_player);
        web = new EWebView(ll_web);

        String url1 = getIntent().getStringExtra("url1");
        String rtmp = getIntent().getStringExtra("rtmp");
        web.html(url1);
        player.rtmp(rtmp);
    }

    public void onSubscribe(View view){
        Intent intent = new Intent(this,WebActivity.class);
        intent.putExtras(getIntent());
        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        web.onDestroy();
        super.onDestroy();
    }
}
